<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="/static/css/index.css">
</head>

<body>



    <h1>登陆页面</h1>

    <a href="/static/html/login.html">登陆</a>

    <a href="/static/html/reg.html">注册</a>

    <a href="/static/html/rpwd.html">修改密码</a>

    <script>





        const xhr = new XMLHttpRequest();
        xhr.open('post', '/api/users/login', true);
        xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
        xhr.send('user=qq&pass=666');
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4 && xhr.status === 200) {
                console.log(xhr.responseText);

                let data = JSON.parse(xhr.responseText);
                console.log(data);

                const { s, txt, token } = data;
                if (s === 1) {
                    // 存储token
                    localStorage.setItem('token', token);

                }
                else {
                    alert('登陆失败')
                }

                // 
            }
        }

    </script>

</body>

</html>